<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="创建人" prop="createUserId">
        <el-input v-model="queryParams.createUserId" placeholder="请输入创建人" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="流程名称" prop="flowName">
        <el-input v-model="queryParams.flowName" placeholder="请输入流程名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="料单类型" prop="receiptTypeOpt">
        <el-input v-model="queryParams.receiptTypeOpt" placeholder="请输入料单类型" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学院" prop="collegeOrgId">
        <el-input v-model="queryParams.collegeOrgId" placeholder="请输入学院" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="经费项目" prop="fundsItem">
        <el-input v-model="queryParams.fundsItem" placeholder="请输入经费项目" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="资产名称" prop="assetName">
        <el-input v-model="queryParams.assetName" placeholder="请输入资产名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="购置日期" prop="purchaseDate">
        <el-date-picker clearable size="small" style="width: 200px" v-model="queryParams.purchaseDate" type="date"
          value-format="yyyy-MM-dd" placeholder="选择购置日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="规格" prop="specs">
        <el-input v-model="queryParams.specs" placeholder="请输入规格" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="单价(元)" prop="unitPrice">
        <el-input v-model="queryParams.unitPrice" placeholder="请输入单价(元)" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="总价(元)" prop="totalPrice">
        <el-input v-model="queryParams.totalPrice" placeholder="请输入总价(元)" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="凭证类型" prop="evidenceTypeOpt">
        <el-input v-model="queryParams.evidenceTypeOpt" placeholder="请输入凭证类型" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="收料人员" prop="receiptorId">
        <el-input v-model="queryParams.receiptorId" placeholder="请输入收料人员" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="经办人员" prop="handlingUserId">
        <el-input v-model="queryParams.handlingUserId" placeholder="请输入经办人员" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="发票" prop="invoiceFileId">
        <el-input v-model="queryParams.invoiceFileId" placeholder="请输入发票" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="料单价格" prop="materialPrice">
        <el-input v-model="queryParams.materialPrice" placeholder="请输入料单价格" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="实验室" prop="labId">
        <el-input v-model="queryParams.labId" placeholder="请输入实验室" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="填单日期" prop="fillDate">
        <el-date-picker clearable size="small" style="width: 200px" v-model="queryParams.fillDate" type="date"
          value-format="yyyy-MM-dd" placeholder="选择填单日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="使用方向" prop="expectUseOpt">
        <el-input v-model="queryParams.expectUseOpt" placeholder="请输入使用方向" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="型号" prop="model">
        <el-input v-model="queryParams.model" placeholder="请输入型号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="厂家" prop="manufactor">
        <el-input v-model="queryParams.manufactor" placeholder="请输入厂家" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="数量" prop="quantity">
        <el-input v-model="queryParams.quantity" placeholder="请输入数量" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="原始凭证" prop="originalVoucher">
        <el-input v-model="queryParams.originalVoucher" placeholder="请输入原始凭证" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="凭证编号" prop="voucherNo">
        <el-input v-model="queryParams.voucherNo" placeholder="请输入凭证编号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="联系人" prop="contactUser">
        <el-input v-model="queryParams.contactUser" placeholder="请输入联系人" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="联系电话" prop="contactMobile">
        <el-input v-model="queryParams.contactMobile" placeholder="请输入联系电话" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['labbase:receipt_form:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['labbase:receipt_form:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['labbase:receipt_form:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5" v-show="false">
        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['labbase:receipt_form:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="receipt_formList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" show-overflow-tooltip></el-table-column>
      <el-table-column label="主键" align="center" prop="receiptId" />
      <el-table-column label="uuid" align="center" prop="uuid" />
      <el-table-column label="创建人" align="center" prop="createUserId" />
      <el-table-column label="流程名称" align="center" prop="flowName" />
      <el-table-column label="料单类型" align="center" prop="receiptTypeOpt" />
      <el-table-column label="学院" align="center" prop="collegeOrgId" />
      <el-table-column label="经费项目" align="center" prop="fundsItem" />
      <el-table-column label="资产名称" align="center" prop="assetName" />
      <el-table-column label="购置日期" align="center" prop="purchaseDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.purchaseDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="规格" align="center" prop="specs" />
      <el-table-column label="单价(元)" align="center" prop="unitPrice" />
      <el-table-column label="总价(元)" align="center" prop="totalPrice" />
      <el-table-column label="凭证类型" align="center" prop="evidenceTypeOpt" />
      <el-table-column label="收料人员" align="center" prop="receiptorId" />
      <el-table-column label="经办人员" align="center" prop="handlingUserId" />
      <el-table-column label="发票" align="center" prop="invoiceFileId" />
      <el-table-column label="料单价格" align="center" prop="materialPrice" />
      <el-table-column label="实验室" align="center" prop="labId" />
      <el-table-column label="填单日期" align="center" prop="fillDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fillDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="使用方向" align="center" prop="expectUseOpt" />
      <el-table-column label="型号" align="center" prop="model" />
      <el-table-column label="厂家" align="center" prop="manufactor" />
      <el-table-column label="数量" align="center" prop="quantity" />
      <el-table-column label="原始凭证" align="center" prop="originalVoucher" />
      <el-table-column label="凭证编号" align="center" prop="voucherNo" />
      <el-table-column label="联系人" align="center" prop="contactUser" />
      <el-table-column label="联系电话" align="center" prop="contactMobile" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['labbase:receipt_form:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['labbase:receipt_form:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改单据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="创建人" prop="createUserId">
          <el-input v-model="form.createUserId" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="流程名称" prop="flowName">
          <el-input v-model="form.flowName" placeholder="请输入流程名称" />
        </el-form-item>
        <el-form-item label="料单类型" prop="receiptTypeOpt">
          <el-input v-model="form.receiptTypeOpt" placeholder="请输入料单类型" />
        </el-form-item>
        <el-form-item label="学院" prop="collegeOrgId">
          <el-input v-model="form.collegeOrgId" placeholder="请输入学院" />
        </el-form-item>
        <el-form-item label="经费项目" prop="fundsItem">
          <el-input v-model="form.fundsItem" placeholder="请输入经费项目" />
        </el-form-item>
        <el-form-item label="资产名称" prop="assetName">
          <el-input v-model="form.assetName" placeholder="请输入资产名称" />
        </el-form-item>
        <el-form-item label="购置日期" prop="purchaseDate">
          <el-date-picker clearable size="small" style="width: 200px" v-model="form.purchaseDate" type="date"
            value-format="yyyy-MM-dd" placeholder="选择购置日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="规格" prop="specs">
          <el-input v-model="form.specs" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item label="单价(元)" prop="unitPrice">
          <el-input v-model="form.unitPrice" placeholder="请输入单价(元)" />
        </el-form-item>
        <el-form-item label="总价(元)" prop="totalPrice">
          <el-input v-model="form.totalPrice" placeholder="请输入总价(元)" />
        </el-form-item>
        <el-form-item label="凭证类型" prop="evidenceTypeOpt">
          <el-input v-model="form.evidenceTypeOpt" placeholder="请输入凭证类型" />
        </el-form-item>
        <el-form-item label="收料人员" prop="receiptorId">
          <el-input v-model="form.receiptorId" placeholder="请输入收料人员" />
        </el-form-item>
        <el-form-item label="经办人员" prop="handlingUserId">
          <el-input v-model="form.handlingUserId" placeholder="请输入经办人员" />
        </el-form-item>
        <el-form-item label="发票" prop="invoiceFileId">
          <el-input v-model="form.invoiceFileId" placeholder="请输入发票" />
        </el-form-item>
        <el-form-item label="料单价格" prop="materialPrice">
          <el-input v-model="form.materialPrice" placeholder="请输入料单价格" />
        </el-form-item>
        <el-form-item label="实验室" prop="labId">
          <el-input v-model="form.labId" placeholder="请输入实验室" />
        </el-form-item>
        <el-form-item label="填单日期" prop="fillDate">
          <el-date-picker clearable size="small" style="width: 200px" v-model="form.fillDate" type="date"
            value-format="yyyy-MM-dd" placeholder="选择填单日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="使用方向" prop="expectUseOpt">
          <el-input v-model="form.expectUseOpt" placeholder="请输入使用方向" />
        </el-form-item>
        <el-form-item label="型号" prop="model">
          <el-input v-model="form.model" placeholder="请输入型号" />
        </el-form-item>
        <el-form-item label="厂家" prop="manufactor">
          <el-input v-model="form.manufactor" placeholder="请输入厂家" />
        </el-form-item>
        <el-form-item label="数量" prop="quantity">
          <el-input v-model="form.quantity" placeholder="请输入数量" type="number"/>
        </el-form-item>
        <el-form-item label="原始凭证" prop="originalVoucher">
          <el-input v-model="form.originalVoucher" placeholder="请输入原始凭证" />
        </el-form-item>
        <el-form-item label="凭证编号" prop="voucherNo">
          <el-input v-model="form.voucherNo" placeholder="请输入凭证编号" />
        </el-form-item>
        <el-form-item label="联系人" prop="contactUser">
          <el-input v-model="form.contactUser" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="contactMobile">
          <el-input v-model="form.contactMobile" placeholder="请输入联系电话" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listReceipt_form,
    getReceipt_form,
    delReceipt_form,
    addReceipt_form,
    updateReceipt_form,
    exportReceipt_form
  } from "@/api/labbase/receipt_form";

  export default {
    name: "Receipt_form",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 单据表格数据
        receipt_formList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          createUserId: null,
          flowName: null,
          receiptTypeOpt: null,
          collegeOrgId: null,
          fundsItem: null,
          assetName: null,
          purchaseDate: null,
          specs: null,
          unitPrice: null,
          totalPrice: null,
          evidenceTypeOpt: null,
          receiptorId: null,
          handlingUserId: null,
          invoiceFileId: null,
          materialPrice: null,
          labId: null,
          fillDate: null,
          expectUseOpt: null,
          model: null,
          manufactor: null,
          quantity: null,
          originalVoucher: null,
          voucherNo: null,
          contactUser: null,
          contactMobile: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          createTime: [{
            required: true,
            message: "创建时间不能为空",
            trigger: "blur"
          }],
          createUserId: [{
            required: true,
            message: "创建人不能为空",
            trigger: "blur"
          }],
          flowName: [{
            required: true,
            message: "流程名称不能为空",
            trigger: "blur"
          }],
          receiptTypeOpt: [{
            required: true,
            message: "料单类型不能为空",
            trigger: "blur"
          }],
          collegeOrgId: [{
            required: true,
            message: "学院不能为空",
            trigger: "blur"
          }],
          assetName: [{
            required: true,
            message: "资产名称不能为空",
            trigger: "blur"
          }],
          purchaseDate: [{
            required: true,
            message: "购置日期不能为空",
            trigger: "blur"
          }],
          evidenceTypeOpt: [{
            required: true,
            message: "凭证类型不能为空",
            trigger: "blur"
          }],
          fillDate: [{
            required: true,
            message: "填单日期不能为空",
            trigger: "blur"
          }],
          expectUseOpt: [{
            required: true,
            message: "使用方向不能为空",
            trigger: "blur"
          }],
          quantity: [{
            required: true,
            message: "数量不能为空",
            trigger: "blur"
          }],
          originalVoucher: [{
            required: true,
            message: "原始凭证不能为空",
            trigger: "blur"
          }],
          voucherNo: [{
            required: true,
            message: "凭证编号不能为空",
            trigger: "blur"
          }],
          contactUser: [{
            required: true,
            message: "联系人不能为空",
            trigger: "blur"
          }],
          contactMobile: [{
            required: true,
            message: "联系电话不能为空",
            trigger: "blur"
          }]
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询单据列表 */
      getList() {
        this.loading = true;
        listReceipt_form(this.queryParams).then(response => {
          this.receipt_formList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          receiptId: null,
          uuid: null,
          createTime: null,
          createUserId: null,
          flowName: null,
          receiptTypeOpt: null,
          collegeOrgId: null,
          fundsItem: null,
          assetName: null,
          purchaseDate: null,
          specs: null,
          unitPrice: null,
          totalPrice: null,
          evidenceTypeOpt: null,
          receiptorId: null,
          handlingUserId: null,
          invoiceFileId: null,
          materialPrice: null,
          labId: null,
          fillDate: null,
          expectUseOpt: null,
          model: null,
          manufactor: null,
          quantity: null,
          originalVoucher: null,
          voucherNo: null,
          contactUser: null,
          contactMobile: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.receiptId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加单据";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const receiptId = row.receiptId || this.ids
        getReceipt_form(receiptId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改单据";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.receiptId != null) {
              updateReceipt_form(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addReceipt_form(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const receiptIds = row.receiptId || this.ids;
        this.$confirm('是否确认删除单据编号为"' + receiptIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delReceipt_form(receiptIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有单据数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportReceipt_form(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      }
    }
  };
</script>
